<template>
  <div
    :class="[
      'loading-screen-container',
      loadingState === 1 ? 'fade' : '',
      loadingState === 2 ? 'hide' : '',
    ]"
  >
    <h2>游戏加载中</h2>
    <div class="bamboo-container">
      <span class="slash left"></span>
      <span class="slash right"></span>
      <img src="/icons/loading_bamboo.svg" alt="Bamboo stand" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { watch } from 'vue';
import { ref } from 'vue';

const props = defineProps(['isLoading']);
const loadingState = ref(0);

watch(
  () => props.isLoading,
  () => {
    if (!props.isLoading) {
      loadingState.value = 1;
      setTimeout(() => {
        loadingState.value = 2;
      }, 1000);
    }
  },
);
</script>

<style scoped lang="scss">
.loading-screen-container {
  display: flex;
  position: absolute;
  top: 0;
  left: 0;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 24px;
  z-index: 2;
  background-image: url('/img/background_text.png');
  background-size: cover;
  background-repeat: no-repeat;
  background-color: var(--dark);
  padding-bottom: 100px;
  width: 100vw;
  height: 100vh;
  text-align: center;
  -webkit-user-drag: none;
  transition: opacity 1000ms ease-in;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;

  h2 {
    position: relative;
    font-weight: 400;
    font-size: 40px;
    font-family: 'Bree serif';
    letter-spacing: 5px;

    &::after {
      display: block;
      position: absolute;
      bottom: 0;
      left: 100%;
      animation: loading-text 1500ms linear infinite;
      content: '';
      color: inherit;
      font-size: inherit;
    }
  }

  .bamboo-container {
    position: relative;
    height: 190px;

    img {
      width: 100px;
      -webkit-user-drag: none;
      -webkit-user-select: none;
      -moz-user-select: none;
      user-select: none;
    }

    .slash {
      display: block;
      position: absolute;
      top: 30%;
      left: -60%;
      width: 225%;

      &::after {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        opacity: 0.7;
        animation: slash 900ms linear infinite;
        border-radius: 50%;
        background: linear-gradient(45deg, #fff 0%, var(--slash) 100%);
        width: 0;
        height: 2px;
        content: '';
      }

      &.left {
        transform: rotateZ(31deg);
        animation: slash-rotation 4500ms linear infinite;
      }

      &.right {
        transform: rotateZ(165deg);
        animation: slash-rotation-2 4000ms linear infinite;
        animation-delay: 600ms;

        &::after {
          animation-duration: 800ms;
          animation-delay: 600ms;
        }
      }
    }
  }

  &.fade {
    opacity: 0;
  }

  &.hide {
    display: none;
  }
}

@keyframes slash {
  0% {
    left: 0;
    opacity: 0;
    width: 0;
  }
  4% {
    opacity: 0;
  }
  5% {
    opacity: 1;
  }
  50% {
    left: 0;
    width: 100%;
  }
  95% {
    opacity: 1;
  }
  96% {
    opacity: 0;
  }
  100% {
    left: 100%;
    opacity: 0;
    width: 0;
  }
}

@keyframes slash-rotation {
  0%,
  19.999% {
    transform: rotateZ(30deg);
  }
  20%,
  39.999% {
    transform: rotateZ(80deg);
  }
  40%,
  59.999% {
    transform: rotateZ(190deg);
  }
  60%,
  79.999% {
    transform: rotateZ(220deg);
  }
  80%,
  99.999% {
    transform: rotateZ(300deg);
  }
}

@keyframes slash-rotation-2 {
  0%,
  19.999% {
    transform: rotateZ(120deg);
  }
  20%,
  39.999% {
    transform: rotateZ(10deg);
  }
  40%,
  59.999% {
    transform: rotateZ(3300deg);
  }
  60%,
  79.999% {
    transform: rotateZ(10deg);
  }
  80%,
  99.999% {
    transform: rotateZ(200deg);
  }
}

@keyframes loading-text {
  0% {
    content: '';
  }
  25% {
    content: '.';
  }
  50% {
    content: '..';
  }
  75% {
    content: '...';
  }
}
</style>
